package Three;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

    @WebServlet("/loginservlet")
    public class Loginservlet extends HttpServlet {
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            req.setCharacterEncoding("utf-8");
            BufferedReader reader = req.getReader();
            String line;
            while((line = reader.readLine()) != null){
                System.out.println(line);
                String[] paramsArr = line.split("&");

                String username = paramsArr[0].split("=")[1];
                String password = paramsArr[1].split("=")[1];

                if("admin".equals(username) && "admin".equals(password)){
                    System.out.println("登入成功！");
                    req.getRequestDispatcher("/SuccessServlet").forward(req,resp);
                }else {
                    System.out.println("登入失败！");
                    req.getRequestDispatcher("/FailServlet").forward(req,resp);
                }
            }
        }

        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            super.doPost(req,resp);
        }
    }


